﻿<Window x:Class="CodeIDX.Views.IndexDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Converters="clr-namespace:CodeIDX.Views.Resources.Converters"
        xmlns:Views="clr-namespace:CodeIDX.Views"
        Title="Index"
        Width="500"
        Height="500"
        WindowStartupLocation="CenterOwner">
    <Grid Margin="5">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="3" />
            <RowDefinition Height="*" />
            <RowDefinition Height="3" />
            <RowDefinition Height="*" />
            <RowDefinition Height="3" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Grid Grid.Row="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="3" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="6" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="3" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="3" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <TextBlock Grid.Column="1"
                       Text="Name" />
            <TextBox x:Name="tbName"
                     Grid.Column="3"
                     Grid.ColumnSpan="3"
                     Text="{Binding Name,
                                    UpdateSourceTrigger=Explicit}"
                     ToolTip="Name of the index" />

            <TextBlock Grid.Row="2"
                       Grid.Column="1"
                       Text="Location" />
            <TextBox x:Name="tbStorePath"
                     Grid.Row="2"
                     Grid.Column="3"
                     IsReadOnly="True"
                     Text="{Binding StorePath,
                                    UpdateSourceTrigger=Explicit}"
                     ToolTip="Location where the index will be created" />

            <Button Grid.Row="2"
                    Grid.Column="5"
                    Click="ChooseStorePath_Click"
                    Content="…"
                    IsEnabled="{Binding IsNew,
                                        RelativeSource={RelativeSource AncestorType={x:Type Views:IndexDialog},
                                                                       Mode=FindAncestor}}"
                    Padding="3,0" />
        </Grid>

        <!--  SourceDirectories  -->
        <Grid Grid.Row="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="3" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="3" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <TextBlock Grid.Row="0"
                       Text="Index sources" />

            <ScrollViewer Grid.Row="2"
                          Grid.Column="0"
                          HorizontalScrollBarVisibility="Auto"
                          VerticalScrollBarVisibility="Auto">
                <TextBox x:Name="tbSourceDirectories"
                         AcceptsReturn="True"
                         Text="{Binding SourceDirectories,
                                        Converter={x:Static Converters:ListToStringConverter.Instance},
                                        UpdateSourceTrigger=Explicit}"
                         TextWrapping="Wrap"
                         ToolTip="One or more directories to index" />
            </ScrollViewer>

            <Button Grid.Row="2"
                    Grid.Column="2"
                    VerticalAlignment="Top"
                    Click="AddDirectory_Click"
                    Content="…"
                    Padding="3,0"
                    ToolTip="Add directory" />
        </Grid>

        <!--  File Filters  -->
        <Grid Grid.Row="4">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="3" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <TextBlock Grid.Row="0"
                       Text="Filetypes" />

            <ScrollViewer Grid.Row="2"
                          VerticalScrollBarVisibility="Auto">
                <TextBox x:Name="tbFileFilters"
                         AcceptsReturn="True"
                         Text="{Binding FileFilters,
                                        Converter={x:Static Converters:ListToStringConverter.Instance},
                                        UpdateSourceTrigger=Explicit}"
                         TextWrapping="Wrap"
                         ToolTip="One or more filetype extensions&#10;Clear to index all filetypes" />
            </ScrollViewer>
        </Grid>

        <Grid Grid.Row="6">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="3" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <Button Grid.Column="1"
                    Width="80"
                    Click="OK_Click"
                    Content="OK"
                    IsDefault="True">
                <Button.IsEnabled>
                    <MultiBinding Converter="{x:Static Converters:ManyBoolsToBoolConverter.Instance}">
                        <Binding Converter="{x:Static Converters:StringNullOrEmptyToBoolReversedConverter.Instance}"
                                 ElementName="tbName"
                                 Path="Text" />
                        <Binding Converter="{x:Static Converters:StringNullOrEmptyToBoolReversedConverter.Instance}"
                                 ElementName="tbStorePath"
                                 Path="Text" />
                        <Binding Converter="{x:Static Converters:StringNullOrEmptyToBoolReversedConverter.Instance}"
                                 ElementName="tbSourceDirectories"
                                 Path="Text" />
                    </MultiBinding>
                </Button.IsEnabled>
            </Button>

            <Button Grid.Column="3"
                    Width="80"
                    Content="Cancel"
                    IsCancel="True" />
        </Grid>
    </Grid>
</Window>
